<?php
class ChallengeOrderVo extends SzAbstractMySqlVo
{

    private $userId;
    private $indexId;
    private $ymd;
    private $status;
    private $isFree;
    private $completeNum;
    private $exp;
    private $gold;
    private $completeOrder;
    private $startTime;
    private $endTime;
    private $reward;
    private $rewardStatus;
    private $rewardTime;
    private $createTime;
    private $updateTime;

    /**
     * Initialize ChallengeOrderVo.
     *
     * @param $userId
     * @param $indexId
     * @param $ymd
     * @param $status
     * @param $isFree
     * @param $completeNum
     * @param $exp
     * @param $gold
     * @param $completeOrder
     * @param $startTime
     * @param $endTime
     * @param $reward
     * @param $rewardStatus
     * @param $rewardTime
     * @param $createTime
     * @param $updateTime
     * @param boolean $isInsert default false, means for now this vo is initialized not for insert process
     * @return ChallengeOrderVo
     */
    public function __construct($userId, $indexId, $ymd, $status, $isFree, $completeNum, $exp, $gold, $completeOrder, $startTime, $endTime, $reward, $rewardStatus, $rewardTime, $createTime, $updateTime, $isInsert = false) {
        $this->userId = $userId;
        $this->indexId = $indexId;
        $this->ymd = $ymd;
        $this->status = $status;
        $this->isFree = $isFree;
        $this->completeNum = $completeNum;
        $this->exp = $exp;
        $this->gold = $gold;
        $this->completeOrder = json_decode($completeOrder, true);
        $this->startTime = $startTime;
        $this->endTime = $endTime;
        $this->reward = json_decode($reward, true);
        $this->rewardStatus = $rewardStatus;
        $this->rewardTime = $rewardTime;
        $this->createTime = $createTime;
        $this->updateTime = $updateTime;

        $this->isInsert = $isInsert;
        $this->voClassName = 'ChallengeOrderVo';
        $this->ormName = 'ChallengeOrder';
    }

    /**
     * @see SzAbstractVo::toArray
     */
    public function toArray($needEncode = false)
    {
        return array(
            'userId' => $this->getUserId(),
            'indexId' => $this->getIndexId(),
            'ymd' => $this->getYmd(),
            'status' => $this->getStatus(),
            'isFree' => $this->getIsFree(),
            'completeNum' => $this->getCompleteNum(),
            'exp' => $this->getExp(),
            'gold' => $this->getGold(),
            'completeOrder' => ($needEncode) ? $this->getCompleteOrder() : $this->getRawCompleteOrder(),
            'startTime' => $this->getStartTime(),
            'endTime' => $this->getEndTime(),
            'reward' => ($needEncode) ? $this->getReward() : $this->getRawReward(),
            'rewardStatus' => $this->getRewardStatus(),
            'rewardTime' => $this->getRewardTime(),
            'createTime' => $this->getCreateTime(),
            'updateTime' => $this->getUpdateTime(),
        );
    }

    /**
     * @see SzAbstractVo::toEntireArray
     */
    public function toEntireArray($needEncode = false)
    {
        return array(
            'userId' => $this->getUserId(),
            'indexId' => $this->getIndexId(),
            'ymd' => $this->getYmd(),
            'status' => $this->getStatus(),
            'isFree' => $this->getIsFree(),
            'completeNum' => $this->getCompleteNum(),
            'exp' => $this->getExp(),
            'gold' => $this->getGold(),
            'completeOrder' => ($needEncode) ? $this->getCompleteOrder() : $this->getRawCompleteOrder(),
            'startTime' => $this->getStartTime(),
            'endTime' => $this->getEndTime(),
            'reward' => ($needEncode) ? $this->getReward() : $this->getRawReward(),
            'rewardStatus' => $this->getRewardStatus(),
            'rewardTime' => $this->getRewardTime(),
            'createTime' => $this->getCreateTime(),
            'updateTime' => $this->getUpdateTime(),
        );
    }

    /**
     * @see SzAbstractVo::toPureArray
     */
    public function toPureArray()
    {
        return array(
            $this->getUserId(),
            $this->getIndexId(),
            $this->getYmd(),
            $this->getStatus(),
            $this->getIsFree(),
            $this->getCompleteNum(),
            $this->getExp(),
            $this->getGold(),
            $this->getCompleteOrder(),
            $this->getStartTime(),
            $this->getEndTime(),
            $this->getReward(),
            $this->getRewardStatus(),
            $this->getRewardTime(),
            $this->getCreateTime(),
            $this->getUpdateTime(),
        );
    }

    public function getUserId()
    {
        return $this->userId;
    }

    public function setUserId($val)
    {
        $this->saveColumnStatus(0, $this->userId);
        $this->userId = $val;
    }

    public function getIndexId()
    {
        return $this->indexId;
    }

    public function setIndexId($val)
    {
        $this->saveColumnStatus(1, $this->indexId);
        $this->indexId = $val;
    }

    public function getYmd()
    {
        return $this->ymd;
    }

    public function setYmd($val)
    {
        $this->saveColumnStatus(2, $this->ymd);
        $this->ymd = $val;
    }

    public function getStatus()
    {
        return $this->status;
    }

    public function setStatus($val)
    {
        $this->saveColumnStatus(3, $this->status);
        $this->status = $val;
    }

    public function getIsFree()
    {
        return $this->isFree;
    }

    public function setIsFree($val)
    {
        $this->saveColumnStatus(4, $this->isFree);
        $this->isFree = $val;
    }

    public function getCompleteNum()
    {
        return $this->completeNum;
    }

    public function setCompleteNum($val)
    {
        $this->saveColumnStatus(5, $this->completeNum);
        $this->completeNum = $val;
    }

    public function getExp()
    {
        return $this->exp;
    }

    public function setExp($val)
    {
        $this->saveColumnStatus(6, $this->exp);
        $this->exp = $val;
    }

    public function getGold()
    {
        return $this->gold;
    }

    public function setGold($val)
    {
        $this->saveColumnStatus(7, $this->gold);
        $this->gold = $val;
    }

    public function getCompleteOrder()
    {
        return json_encode($this->completeOrder);
    }

    public function getRawCompleteOrder()
    {
        return $this->completeOrder;
    }

    public function setCompleteOrder($val)
    {
        $encodedLength = SzUtility::strLen(json_encode($val));
        if ($encodedLength > 12800) {
            SzLogger::get()->error('[ChallengeOrderVo] The length of column completeOrder exceed the limit, length / limit: ' . $encodedLength . ' / 12800');
            throw new SzException(10522, array('ChallengeOrderVo', '12800', $encodedLength));
        } else if ($encodedLength > 11520) {
            SzLogger::get()->warn('[ChallengeOrderVo] The length of column completeOrder exceed the warning level, length / limit: ' . $encodedLength . ' / 12800');
        }
        $this->saveColumnStatus(8, $this->completeOrder);
        $this->completeOrder = $val;
    }

    public function getStartTime()
    {
        return $this->startTime;
    }

    public function setStartTime($val)
    {
        $this->saveColumnStatus(9, $this->startTime);
        $this->startTime = $val;
    }

    public function getEndTime()
    {
        return $this->endTime;
    }

    public function setEndTime($val)
    {
        $this->saveColumnStatus(10, $this->endTime);
        $this->endTime = $val;
    }

    public function getReward()
    {
        return json_encode($this->reward);
    }

    public function getRawReward()
    {
        return $this->reward;
    }

    public function setReward($val)
    {
        $encodedLength = SzUtility::strLen(json_encode($val));
        if ($encodedLength > 128) {
            SzLogger::get()->error('[ChallengeOrderVo] The length of column reward exceed the limit, length / limit: ' . $encodedLength . ' / 128');
            throw new SzException(10522, array('ChallengeOrderVo', '128', $encodedLength));
        } else if ($encodedLength > 115) {
            SzLogger::get()->warn('[ChallengeOrderVo] The length of column reward exceed the warning level, length / limit: ' . $encodedLength . ' / 128');
        }
        $this->saveColumnStatus(11, $this->reward);
        $this->reward = $val;
    }

    public function getRewardStatus()
    {
        return $this->rewardStatus;
    }

    public function setRewardStatus($val)
    {
        $this->saveColumnStatus(12, $this->rewardStatus);
        $this->rewardStatus = $val;
    }

    public function getRewardTime()
    {
        return $this->rewardTime;
    }

    public function setRewardTime($val)
    {
        $this->saveColumnStatus(13, $this->rewardTime);
        $this->rewardTime = $val;
    }

    public function getCreateTime()
    {
        return $this->createTime;
    }

    public function setCreateTime($val)
    {
        $this->saveColumnStatus(14, $this->createTime);
        $this->createTime = $val;
    }

    public function getUpdateTime()
    {
        return $this->updateTime;
    }

    public function setUpdateTime($val)
    {
        $this->saveColumnStatus(15, $this->updateTime);
        $this->updateTime = $val;
    }

}